/**
 * 2010(c) Copyright Oceansoft Information System Co.,LTD. All rights reserved.
 * <p>
 * Compile: JDK1.6+
 * <p>
 * 版权所有(C)：江苏欧索软件有限公司
 * <p>
 * 公司名称：江苏欧索软件有限公司
 * <p>
 * 公司地址：苏州新区青山路1号索迪实训基地
 * <p>
 * 网址: http://www.oceansoft.com.cn
 * <p>
 * 版本: 权力阳光数据管理平台_1.0
 * <p>
 * 作者: 110510(朱伟家)
 * <p>
 * <p>
 * 文件名: SMSUtil.java
 * <p>
 * 类产生时间:2014-12-21 上午10:25:42
 * <p>
 * 负责人: 110510(朱伟家)
 * <p>
 * 所在组: 权力阳光数据管理平台
 * <p>
 * 所在部门: 开发一部-技术二部
 * <p>
 * email：zhuwj@oceansoft.com.cn
 * <p>
 * <p>
 */

package com.oceansoft.mobile.econsole.task.sms;


import javax.xml.namespace.QName;
import javax.xml.rpc.Call;

public class SMSUtil {

    private static final String APP_ID = "467";
    private static final String MODULE_ID = "";
    private static final String SMS_TYPE = "1";
    private static final String ENDPOINT = "http://172.16.1.236:8084/smsplat/services/smsService";

    /**
     * 发送短信
     *
     * @param pk        业务主键
     * @param message   短信内容
     * @param receivers 接收人，多个接收人使用英文逗号分割
     */
    public static void sendSMS(String pk, String message, String receivers) {
        String METHOD = "sendMessage";
        try {
            org.apache.axis.client.Service service1 = new org.apache.axis.client.Service();
            Call call = service1.createCall();
            call.setTargetEndpointAddress(ENDPOINT);
            call.setOperationName(new QName(METHOD));

            call.addParameter("businesspk", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("appId", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("moduleId", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("type", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("receiveNos", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("message", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);

            Object[] params = new Object[6];
            params[0] = pk;
            params[1] = APP_ID;
            params[2] = MODULE_ID;
            params[3] = SMS_TYPE;
            params[4] = receivers;
            params[5] = message;
            call.invoke(params);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void sendSMS(String pk, String message, String receivers,String moduleId) {
        String METHOD = "sendMessage";
        try {
            org.apache.axis.client.Service service1 = new org.apache.axis.client.Service();
            Call call = service1.createCall();
            call.setTargetEndpointAddress(ENDPOINT);
            call.setOperationName(new QName(METHOD));

            call.addParameter("businesspk", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("appId", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("moduleId", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("type", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("receiveNos", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("message", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);

            Object[] params = new Object[6];
            params[0] = pk;
            params[1] = APP_ID;
            params[2] = moduleId;
            params[3] = SMS_TYPE;
            params[4] = receivers;
            params[5] = message;
            call.invoke(params);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 接收短信
     *
     * @param startDate 短信接收开始日期
     * @param endDate   短信接收截止日期
     * @return String 多条短信内容集合
     */
    public static String receiveSMS(String startDate, String endDate) {
        String METHOD = "receiveMessage";
        try {
            org.apache.axis.client.Service service1 = new org.apache.axis.client.Service();
            Call call = service1.createCall();

            call.setTargetEndpointAddress(ENDPOINT);
            call.setOperationName(new QName(METHOD));
            call.addParameter("appId", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("moduleId", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("startDate", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.addParameter("endDate", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);

            Object[] params = new Object[4];
            params[0] = APP_ID;
            params[1] = MODULE_ID;
            params[2] = startDate;
            params[3] = endDate;
            return (String) call.invoke(params);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static void main(String[] args) {
//        sendSMS("KC123456","中文测试", "15195668256");
        System.out.println("=====>" + receiveSMS("20141221204412", "20141221205412"));
    }
}
